package com.example.pingke;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class IndexFragment extends Fragment {
	private String test[] = new String[] { "小鬼头", "猪一只", "OMG" };
	private List<Map<String, Object>> mList;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_index, container,
				false);
		setupComponent(rootView);
		return rootView;
	}

	private void setupComponent(View rootView) {
		mList = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < test.length; i++) {
			Map<String, Object> item = new HashMap<String, Object>();
			item.put("indexName", test[i]);
			mList.add(item);
		}
		SimpleAdapter adapter = new SimpleAdapter(rootView.getContext(), mList,
				R.layout.index_item, new String[] { "indexName" },
				new int[] { R.id.indexName });
		ListView indexList = (ListView) rootView.findViewById(R.id.indexList);
		indexList.setAdapter(adapter);
		indexList.setTextFilterEnabled(true);
		indexList.setOnItemClickListener(listViewOnItemClkLis);
	}

	AdapterView.OnItemClickListener listViewOnItemClkLis = new AdapterView.OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {

		}

	};
}
